package com.fxu.framework.core.enums;

import com.fxu.framework.biz.base.Limits;
import lombok.AllArgsConstructor;
import lombok.Getter;

/***
 * 审批流程状态字段字符串枚举
 * @author fangxu
 * @version 1.5.2
 ***/
@AllArgsConstructor
public enum AuditStatus implements BaseEnum<String, String> {
    //Pending:待处理,Cancel:已作废,Doing:审核中,Failed:审核失败,Finish:已完成
    Pending("Pending", "待处理", 0),
    Cancel("Cancel", "已作废", 9),
    Doing("Doing", "审核中", 1),
    Failed("Failed", "审核失败", 3),
    Finish("Finish", "已完成", 2)
    ;

    final String code;
    final String desc;
    final Integer value;

    @Override
    public String code() {
        return code;
    }

    @Override
    public String desc() {
        return desc;
    }

    public Integer value() {
        return value;
    }

    public static String desc(String code) {
        AuditStatus ret = find(code);
        return ret == null ? null : ret.desc;
    }

    public static AuditStatus find(String code) {
        return code == null ? null : BaseEnum.findOne(values(), v -> v.code.equals(code));
    }

    public static AuditStatus find(Integer value) {
        return value == null ? null : BaseEnum.findOne(values(), v -> v.value.equals(value));
    }

    public static boolean is(String limits) {
        AuditStatus[] enums = AuditStatus.values();
        String[] array = new Limits(limits).getArray();
        for (AuditStatus e : enums) {
            if (BaseEnum.findOne(array, v -> v.equals(e.code + Limits.SPLIT_CHILD + e.desc)) == null) {
                return false;
            }
        }
        for (String s : array) {
            if (BaseEnum.findOne(enums, v -> s.equals(v.code + Limits.SPLIT_CHILD + v.desc)) == null) {
                return false;
            }
        }
        return true;
    }
}